package demo2;

import java.util.*;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
//用来比较年龄的比较器
class CompareAge implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
public class Test {
    public static void main(String[] args) {
        CompareAge compareAge = new CompareAge();
        //传进入一个比较器
        Queue<Student> priorityQueue = new PriorityQueue<>(compareAge);
        Student stu1 = new Student("张三",22);
        Student stu2 = new Student("李四",12);
        priorityQueue.offer(stu1);
        priorityQueue.offer(stu2);
        System.out.println(stu1.compareTo(stu2));
        System.out.println(priorityQueue.poll().name);
        Queue<Student> pri = new PriorityQueue<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.age - o1.age;
            }
        });
    }
}
